﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace Zadani09.db
{
    public class AtributEqualityComparer<T> : IEqualityComparer<T>
    {
        private string atribut;

        public AtributEqualityComparer(string atribut)
        {
            this.atribut = atribut;
        }

        public bool Equals(T x, T y)
        {
            if (atribut == null || atribut.Length <= 0) return (false);

              // overeni typu argumentu
            if (!(x is IAtribut) || !(y is IAtribut))
            {
                throw new Exception("Zadané argumenty nejsou typu IAtribut.");
            }

              // pretypovani na spravny typ
            IAtribut t1 = (IAtribut)x;
            IAtribut t2 = (IAtribut)y;

            return (t1[atribut].ToString() == t2[atribut].ToString());
        }

        public int GetHashCode(T obj)
        {
              // overeni typu argumentu
            if (!(obj is IAtribut))
            {
                throw new Exception("Zadaný argument není typu IAtribut.");
            }

              // pretypovani na spravny typ
            IAtribut t = (IAtribut)obj;

            return (t[atribut].GetHashCode());
        }
    }
}
